home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / csim / source.lha / source / C++SIM / lwp_thread.h < prev    next >
C/C++ Source or Header  |  1993-06-14  |  2KB  |  57 lines

  1. /*
  2.  * Copyright (C) 1993
  3.  *
  4.  * Department of Computing Science,
  5.  * The University,
  6.  * Newcastle upon Tyne,
  7.  * UK.
  8.  */
  9.  
  10. #ifndef LWP_THREAD_H_
  11. #define LWP_THREAD_H_
  12.  
  13. #include <lwp/lwp.h>
  14.  
  15. #ifndef THREAD_H_
  16. #include "thread.h"
  17. #endif
  18.  
  19. /* This is the Sun thread implementation of the Thread virtual class. It provides
  20.  * an implementation for all of the pure virtual functions declared in the Thread
  21.  * base class.
  22.  * The Initialize function must be called at the start of any program which uses the
  23.  * threads implementation as it calls necessary Sun thread initialization routines.
  24.  *
  25.  * Note: if any problems occur when using the Sun thread package, try increasing the
  26.  * stack size and/or the number of stacks to create in Initialize.
  27.  */
  28.  
  29. class LWP_Thread : public Thread
  30. {
  31. public:
  32.     virtual void Suspend ();                // Suspend an active thread
  33.     virtual void Resume ();                 // Resume a suspended thread
  34.     virtual void Sleep (struct timeval);    // Put active thread to sleep for duration specified
  35.  
  36.     virtual void Body () = 0;               // Body of "active" object (defined in the deriving class)
  37.     virtual long Current_Thread () const;   // Returns current thread id
  38.  
  39.     thread_t Thread_ID () const;            // Returns current thread's Sun thread_key
  40.  
  41.     // Initialize must be called exactly once at the start of the program
  42.     static void Initialize ();
  43.  
  44. protected:
  45.     static const int MaxPriority;           // Maximum priority of a thread
  46.  
  47.     LWP_Thread (int priority = MaxPriority); // Create thread with given (or maximum) priority
  48.     LWP_Thread (thread_t);                  // Create thread with given Sun thread_key
  49.     virtual ~LWP_Thread ();
  50.  
  51. private:
  52.     static void Execute (LWP_Thread*);     // This routine calls the 'main' object code
  53.     thread_t mid;
  54. };
  55.  
  56. #endif
  57.